<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Usuario
 *
 */
class User_Model_User extends Zend_Db_Table_Abstract {
    
    protected $_name = 'sys_user';

    public function autenticar(array $values){
        $db = $this->getAdapter();
        $filas = $db->select()
            ->from($this->_name)
            ->where('username = ?', $values['username'])
            ->where('password = ?', md5($values['password']))
            ->query()->fetchAll();
        $loginValido = count($filas)===1;
        if($loginValido){
            $regLogin = Zend_Registry::get('login');
            $regLogin->rg_usuario = $filas[0];
//            echo"<br>regLogin: ";var_dump($regLogin);
//            echo"<br>regLogin->users: ";var_dump($regLogin->usuario);die();
        }
        //return $loginValido;
        return $filas[0];
    }


 /***********************************************************/
    public function getStateUser($username){
        $db = $this->getAdapter();
       

        $filas = $db->select()
            ->from($this->_name, array('state'))
            ->where('username = ?',$username);

            //->query()->fetchRow ->fetch();
        $state = $db->fetchRow($filas);

        if(isset($state['state'])){
			switch($state['state']){
				case 1:
					$state = "ACTIVE";
				break;
				case 2:
					$state = "LOCKED";
				break;
				case 3:
					$state = "DELETED";
				break;
				case 4:
					$state = "FLOGIN";
				break;
				case 5:
					$state = "RESET";
				break;

			}
			return $state;

		}else{
			return '';
		}
    }
 



}
